/**
 * 
 */
package model;

import java.util.ArrayList;

import org.apache.log4j.Logger;

import persistence.Message;

import listeners.Observable;
import listeners.Observer;

/**
 * @author Administrateur
 *
 */
public abstract class AbstractModel implements Observable{
	private Message model;
	private ArrayList<Observer> observers;
	protected Logger logger = Logger.getLogger(AbstractModel.class);
	/**
	 * 
	 */
	public AbstractModel() {
		this.model = new Message();
		setObservers(new ArrayList<Observer>());
	}
	/**
	 * @param observers the observers to set
	 */
	public void setObservers(ArrayList<Observer> observers) {
		this.model = new Message();
		this.observers = observers;
	}
	/**
	 * @return the observers
	 */
	public ArrayList<Observer> getObservers() {
		return observers;
	}
	/**
	 * @param model the model to set
	 */
	public void setModel(Message model) {
		this.model = model;
	}
	/**
	 * @return the model
	 */
	public Message getModel() {
		return model;
	}
	
	@Override
	public void addObserver(Observer obs) {
		getObservers().add(obs);		
	}

	@Override
	public void removeObserver() {
		setObservers(new ArrayList<Observer>());	
	}

	@Override
	public void notifyObserver(Message msg) {
		for(Observer obs : getObservers())
			obs.update(msg);
	}

}
